# Imports
# -------
import wx

# --------------------------
class TopicDialog(wx.Dialog):
# --------------------------
	# -----------------------------------------------------------
	def __init__(self, parent, id, imageTopics, annotationTopics):
	# -----------------------------------------------------------
		# Super!
		wx.Dialog.__init__(self, parent, id, 'Topics', size=(360, 185))

		# Silly workaround for determining how the dialog is closed
		self.okPressed = False

		# Initialize the selection
		self.selection = None

		# Layout the dialog box
		sizer = wx.BoxSizer(wx.VERTICAL)
		sizer.AddSpacer(10)

		# Image topic	
		imageSizer = wx.BoxSizer(wx.HORIZONTAL)
		imageLabel = wx.StaticText(self, label='Image topic:           ')
		imageSizer.Add(imageLabel, 0, wx.ALIGN_LEFT)
		self.imageTopicCombo = wx.ComboBox(self, wx.ID_ANY, choices = imageTopics, value = imageTopics[0])
		imageSizer.Add(self.imageTopicCombo, 0, wx.ALIGN_RIGHT | wx.EXPAND)
		sizer.Add(imageSizer, 0, wx.EXPAND)
		sizer.AddSpacer(5)

		# Annotation topic		
		annotationSizer = wx.BoxSizer(wx.HORIZONTAL)
		annotationTopics += ['[New annotation topic]', '[Load external annotation bag]']
		headerLabel = wx.StaticText(self, label='Annotation topic:     ')
		annotationSizer.Add(headerLabel, 0, wx.ALIGN_LEFT)
		self.annotationTopicCombo = wx.ComboBox(self, wx.ID_ANY, choices = annotationTopics, value = annotationTopics[0])
		annotationSizer.Add(self.annotationTopicCombo, 0, wx.ALIGN_RIGHT | wx.EXPAND)
		sizer.Add(annotationSizer, 0, wx.EXPAND)
		sizer.AddSpacer(12)

		# Rectify image?
		optionsLabel = wx.StaticText(self, label='Additional Options:')
		sizer.Add(optionsLabel)
		self.rectifyCheckBox = wx.CheckBox(self, wx.ID_ANY, 'Rectify Images')
		self.rectifyCheckBox.SetValue(True)
		sizer.Add(self.rectifyCheckBox)

		# Shuffle?
		self.shuffleCheckBox = wx.CheckBox(self, wx.ID_ANY, 'Shuffle Images')
		self.shuffleCheckBox.SetValue(False)
		sizer.Add(self.shuffleCheckBox)
		
		# OK button
		okButton = wx.Button(self, wx.ID_ANY, 'Ok')
		sizer.Add(okButton, 0, wx.ALIGN_CENTER | wx.EXPAND)
		self.Bind(wx.EVT_BUTTON, self.onOK, okButton)
		
		# Set the sizer
		hSizer = wx.BoxSizer(wx.HORIZONTAL)
		hSizer.AddSpacer(10)
		hSizer.Add(sizer, wx.EXPAND | wx.ALIGN_CENTER)
		hSizer.AddSpacer(10)
		self.SetSizer(hSizer)
		self.Layout()

	# -------------------
	def onOK(self, event):
	# -------------------
		# Silly workaround for determining how the dialog is closed
		self.okPressed = True

		self.annotationTopic = self.annotationTopicCombo.GetValue()
		self.imageTopic = self.imageTopicCombo.GetValue()
		self.rectify = self.rectifyCheckBox.GetValue()
		self.shuffle = self.shuffleCheckBox.GetValue()
		self.Destroy()
